package com.web.common.iot.mqtt.api;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import com.web.common.api.config.ServiceInstanceName;
import com.web.common.iot.mqtt.entity.MqttConnectedListener;
import com.web.common.iot.mqtt.entity.MqttDeliveredListener;
import com.web.common.iot.mqtt.entity.MqttDisconnectedListener;
import com.web.common.iot.mqtt.entity.MqttDroppedListener;
import com.web.common.iot.mqtt.entity.MqttSubscribedListener;
import com.web.common.result.R;

@FeignClient(name = ServiceInstanceName.SERVICE_IOT_NAME, contextId = "mqttListenApi", path = "/iot/mqtt/listen")
public interface MqttListenApi {

	/**
	 * MQTT连接完成时推送消息
	 * @param connected 已经连接完成
	 * @return R<Object> 处理结果
	 *
	 * @author zhouhui
	 * @since 1.0.0
	 */
	@PostMapping(path = "/connected")
	@ResponseBody
	R<Object> connectedEvent(@RequestBody MqttConnectedListener connected);
	
	/**
	 * MQTT连接断开时推送消息
	 * @param disconnected 断开连接 
	 * @return R<Object> 处理结果
	 *
	 * @author zhouhui
	 * @since 1.0.0
	 */
	@PostMapping(path = "/disconnected")
	@ResponseBody
	R<Object> disconnectedEvent(@RequestBody MqttDisconnectedListener disconnected);
	
	/**
	 * MQTT客户端进行主题订阅时推送
	 * @param subscribed 主题订阅相关信息
	 * @return R<Object> 处理结果
	 *
	 * @author zhouhui
	 * @since 1.0.0
	 */
	@PostMapping(path = "/subscribed")
	@ResponseBody
	R<Object> subscribedEvent(@RequestBody MqttSubscribedListener subscribed);
	
	/**
	 * MQTT客户端进行取消主题订阅时推送
	 * @param subscribed 取消主题订阅相关信息
	 * @return R<Object> 处理结果
	 *
	 * @author zhouhui
	 * @since 1.0.0
	 */
	@PostMapping(path = "/unsubscribed")
	@ResponseBody
	R<Object> unsubscribedEvent(@RequestBody MqttSubscribedListener subscribed);
	
	/**
	 * 当消息被放入底层socket时触发
	 * @param delivered 投递消息内容
	 * @return R<Object> 处理结果
	 *
	 * @author zhouhui
	 * @since 1.0.0
	 */
	@PostMapping(path = "/delivered")
	@ResponseBody
	R<Object> deliveredEvent(@RequestBody MqttDeliveredListener delivered);
	
	/**
	 * 消息被丢弃触发
	 * @param dropped 被丢弃的数据信息
	 * @return R<Object> 处理结果
	 *
	 * @author zhouhui
	 * @since 1.0.0
	 */
	@PostMapping(path = "/dropped")
	@ResponseBody
	R<Object> droppedEvent(@RequestBody MqttDroppedListener dropped);
}
